package com.yulongtian.oneProblemEveryDay.month202211.day20221130;

/**
 * https://leetcode.cn/problems/check-if-array-is-sorted-and-rotated/submissions/
 * 可
 *
 * @author yulongTian
 * @create 2022-11-30 15:53
 */
public class Test01 {
    public static void main(String[] args) {
        int[] nums = {1, 1, 1};
        System.out.println(check(nums));
    }

    public static boolean check(int[] nums) {

        int len = nums.length;


        int oneIndex = 0;
        int[] raw = new int[2 * len];
        for (int i = 0; i < len; i++) {
            raw[i] = nums[i];
            raw[i + len] = nums[i];
        }

        for (int i = 0; i < raw.length; i++) {
            if (i == len * 2 - 1) {
                return true;
            }
            if (raw[i + 1] < raw[i]) {
                oneIndex = i + 1;
                break;
            }
        }

        for (int i = 0; i < len - 1; i++) {
            if (raw[i + oneIndex] > raw[i + oneIndex + 1]) {
                return false;
            }
        }

        return true;
    }

}
